package com.restaurant.web.android.service;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.restaurant.domain.Menu;
import com.restaurant.service.MenuService;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;

@Component
@RequestMapping("/loadAllMenuList.do")
public class MenuController {
	
	@Autowired
	private MenuService objMenuService;
	
	@RequestMapping(method=RequestMethod.POST)
	public void menuControllerPostMethod(HttpServletRequest request, HttpServletResponse response){
		XStream objXStream = new XStream(new DomDriver());
		objXStream.alias("menu", Menu.class);
		objXStream.alias("list", List.class);
		
		List<Menu> listMenus = null;
		try {
			listMenus = objMenuService.loadByHql("from Menu where isdeleted = false  and menucategory.menucategoryID = " + request.getParameter("menuCategoryID"));
			response.getWriter().print(objXStream.toXML(listMenus));
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
